package com.example.wan_android.adapter

import androidx.lifecycle.LifecycleOwner
import com.bumptech.glide.Glide
import com.example.wan_android.BR
import com.example.wan_android.R
import com.example.wan_android.core.CoreViewHolder
import com.example.wan_android.databinding.AdapterBannerBinding
import com.example.wan_android.http.bean.BannerItem
import com.example.wan_android.viewmodel.PaperShowViewModel

class MainBannerAdapter(
    private val lifecycleOwner: LifecycleOwner,
    private val sharedViewModel: PaperShowViewModel // 外部传入共享的 ViewModel
)  : CoreAdapter<AdapterBannerBinding, PaperShowViewModel, BannerItem>(
    BR.data,
    BR.viewModel,
    sharedViewModel
) {
    override fun getItemLayoutId(viewType: Int): Int {
        return R.layout.adapter_banner
    }

    override fun onBindViewHolder(holder: CoreViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        // 设置 LifecycleOwner
        holder.binding.lifecycleOwner = lifecycleOwner

        Glide.with(holder.binding.root.context)
            .load(mListData[position].imagePath)
            .into(holder.binding.root.findViewById<androidx.appcompat.widget.AppCompatImageView>(R.id.iv_banner))
    }


}